package util;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.io.FileUtils;
import org.testng.annotations.Test;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;

public class Teest {
    String data;

    {
        try {
            data = FileUtils.readFileToString(new File("./data/1.json"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    JSONArray jsonArray=JSONArray.parseArray(data);
    List<Object> list= JSONObject.parseArray(jsonArray.toJSONString(),Object.class);
    @Test
    public void test_01() throws IOException {
        for(int i=0;i<list.size();i++){
            Map<String,Object> map= (Map<String, Object>) list.get(i);
            List<Object> lists = (List<Object>) map.get("receivableRecordLists");
            for (int j=0;j< lists.size();j++){
                Map<String,Object> map_list= (Map<String, Object>) lists.get(j);
                map_list.put("entrustmentCode","11111");
            }

        }
        System.out.println("list="+list);
        System.out.println("data======"+jsonArray);
        FileUtils.writeStringToFile(new File("./data/1.json"), String.valueOf(list),"UTF-8");


    }
//    @Test
//    public static void test_01(){
//        try {
//            String s1 = readFileByLines("C:\\Users\\admin\\Desktop\\json.config");    // 读取配置文件
//            String ws = null;
//            BufferedWriter bw = new BufferedWriter(new FileWriter("C:\\Users\\admin\\Desktop\\json2.config"));   // 输出配置文件
//            JSONArray dataJson = JSONArray.fromObject(s1);
//            for (int i = 0; i < dataJson.size(); i++) {
//                JSONObject properties = (JSONObject) dataJson.get(i);
//                properties.put("confKey","repalceParams");     //  需要替换的参数
//                ws = dataJson.toString();
//                System.out.println(ws);
//            }
//            bw.write(ws);
//            bw.flush();
//            bw.close();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//
//
//    }
}
